﻿using System; 
using System.Reflection; 
namespace docmgr.Model { 
                           
	public class Department{ 	

		#region 私有属性成员 
		
		int m_ID; //ID 
		string m_Name; //部门名称 
		string m_Remark; //备注 
 
		protected string m_Tag; // 预定义属性 
		
		#endregion
		
		#region 构造函数 Constructors 
		public Department(){
					// m_ID = 0 ;
		// m_Name = "" ;
		// m_Remark = "" ;

		}
		//public Department(int ID,string Name,string Remark, string Tag){
					// m_ID = ID ;
		// m_Name = Name ;
		// m_Remark = Remark ;

			//m_Tag = Tag;
		//}
		#endregion
		
		#region 公共属性成员 
		

		/// <summary>
		/// ID
		/// <summary>
		public int ID 
		{
                                         get { return m_ID; }
                                         set { m_ID = value;}
		}


		/// <summary>
		/// 部门名称
		/// <summary>
		public string Name 
		{
                                         get { return m_Name; }
                                         set { m_Name = value;}
		}


		/// <summary>
		/// 备注
		/// <summary>
		public string Remark 
		{
                                         get { return m_Remark; }
                                         set { m_Remark = value;}
		}


		 
        /// <summary>
		/// 附加备用属性
		/// <summary>
		public string Tag {
			get { return m_Tag; }
			set { m_Tag = value; }
		}
		#endregion
		
        #region 扩展公共属性
		//-
		protected static string[] m_FiledsInfo=new string[]{
		  		"ID,int,ID",
		"Name,varchar,部门名称",
		"Remark,varchar,备注",

		  "Tag,varchar,扩展备用属性" //注意该字段不存在于数据库表
		};
            
        /// <summary>
        /// 类对应的表结构信息,
        /// 记录 列的名称、数据类型和大小。
        /// </summary>
        public static string[] FiledsInfo {
            get {
                return m_FiledsInfo;
            }
        }
            

        /// <summary>
        /// 属性索引器
        /// </summary>
        /// <param name=\"index\"></param>
        /// <returns></returns>
        public object this[int index] {
            get {
                return this.getValue(m_FiledsInfo[index].Split(new char[] { ',' })[0]);
            }
            set {
                this.setValue(m_FiledsInfo[index].Split(new char[] { ',' })[0], value);
            }
        }
            
        /// <summary>
        /// 重载属性索引器
        /// </summary>
        /// <param name=\"name\"></param>
        /// <returns></returns>
        public object this[string name] {
            get {
                return this.getValue(name);
            }
            set {
                this.setValue(name, value);
            }
        }       
	 
        /// <summary>
        /// 根据属性名称赋值
        /// 请注意参数name必须完全等于类的某个属性，可以忽略大小写，
        /// </summary>
        /// <param name="name">属性名称</param>
        /// <param name="value">属性值</param>
        public void setValue(string name, object value)
        {
            PropertyInfo pinfo = this.GetType().GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            if (pinfo != null)
            {
                try
                {
                    pinfo.SetValue(this, Convert.ChangeType(value, pinfo.PropertyType), null);
                }
                catch
                {
                    throw new System.Exception("输入参数转换格式时出错！\n输入参数：" + value.ToString() + "\n转换格式：" + pinfo.PropertyType.ToString());
                }

            }
        }

        /// <summary>
        /// 根据属性名称取值
        /// 请注意参数name必须完全等于类的某个属性，可以忽略大小写，
        /// </summary>
        /// <param name="name">属性名称</param>
        public object getValue(string name)
        {
            PropertyInfo pinfo = this.GetType().GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
            if (pinfo != null)
                return pinfo.GetValue(this, BindingFlags.IgnoreCase, null, null, null);
            else
                return null;
        }
        #endregion
			     
	}
}